package com.lanou.controller;
import com.lanou.service.ShoppingService;
import com.lanou.utils.AjaxResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.List;

/**
 * Created by dllo on 18/3/19.
 */
@Controller
public class ShoppingController {
    @Resource
    private ShoppingService shoppingService;

    /**
     * @desc 由购物车生成订单(对应不同的订单状态)根据状态修改T8T_shopping表
     * @author 李振鹏
     * @date 3/19/16:47
     * @param cartIDs 购物车条目集合
     * @param payStatus 状态
     * @desc payStatus状态说明:{null:下单未支付(待付款状态),3:付款(待发货),
     *                           5:确认收货(待评价状态),6:已完成(已评价状态),
     *                           7:退款状态}
     * @return json数据格式, 内含有修改成功信息
     */
    @ResponseBody
    @RequestMapping(value = "/shoppingOrders")
    public AjaxResult shoppingOrders(@RequestParam(value = "cartIDs") List<Integer> cartIDs,
                                     @RequestParam("userID") Integer userID,
                                     @RequestParam(value = "payStatus", required = false) Integer payStatus) {
        AjaxResult ajaxResult=null;
        //接受到集合,进行生成订单操作
        for (int i = 0; i < cartIDs.size(); i++) {
            int cartID = cartIDs.get(i);
            ajaxResult = shoppingService.shoppingOrders(cartID,userID, payStatus);
        }
        return ajaxResult;
    }

    /**
     * @desc 通过用户id和订单状态动态查询T8T_shopping表
     * @author 李振鹏
     * @date 3/19/16:47
     * @param userID 用户ID
     * @param shoppingStatusID 查询订单状态
     * @desc 状态说明[全部(值为 null)or待付款(值为 2)or待发货(值为 3)or待收货(值为 4)or待评价(值为 5)or退款(值为 7)]
     * @return json数据格式, 内含订单信息集合
     *
     */
    @ResponseBody
    @RequestMapping(value = "/ordersDetails")
    public AjaxResult ordersDetails(@RequestParam("userID") Integer userID,
                                    @RequestParam(value = "shoppingStatus_id",required = false) Integer shoppingStatusID) {
        return shoppingService.shoppingOrdersDetails(userID, shoppingStatusID);
    }
}
